{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n    @Author: King\\n    @Date: 2019.06.25\\n    @Purpose: Graph Convolutional Network\\n    @Introduction:   This is a gentle introduction of using DGL to implement \\n                    Graph Convolutional Networks (Kipf & Welling et al., \\n                    Semi-Supervised Classification with Graph Convolutional Networks). \\n                    We build upon the earlier tutorial on DGLGraph and demonstrate how DGL \\n                    combines graph with deep neural network and learn structural representations.\\n    @Datasets: \\n    @Link : \\n    @Reference : https://docs.dgl.ai/tutorials/models/1_gnn/1_gcn.html\\n'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "    @Author: King\n",
    "    @Date: 2019.06.25\n",
    "    @Purpose: Graph Convolutional Network\n",
    "    @Introduction:   This is a gentle introduction of using DGL to implement \n",
    "                    Graph Convolutional Networks (Kipf & Welling et al., \n",
    "                    Semi-Supervised Classification with Graph Convolutional Networks). \n",
    "                    We build upon the earlier tutorial on DGLGraph and demonstrate how DGL \n",
    "                    combines graph with deep neural network and learn structural representations.\n",
    "    @Datasets: \n",
    "    @Link : \n",
    "    @Reference : https://docs.dgl.ai/tutorials/models/1_gnn/1_gcn.html\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Relational Graph Convolutional Network\n",
    "\n",
    "A knowledge graph is made up by a collection of triples of the form (subject, relation, object). Edges thus encode important information and have their own embeddings to be learned. Furthermore, there may exist multiple edges among any given pair.\n",
    "\n",
    "A recent model Relational-GCN (R-GCN) from the paper Modeling Relational Data with Graph Convolutional Networks is one effort to generalize GCN to handle different relations between entities in knowledge base. This tutorial shows how to implement R-GCN with DGL.\n",
    "最近的模型Relational-GCN（R-GCN）来自使用图卷积网络建模关系数据的论文，是一种推广GCN以处理知识库中实体之间的不同关系的努力。本教程介绍如何使用DGL实现R-GCN。\n",
    "\n",
    "\n",
    "## R-GCN: a brief introduction\n",
    "\n",
    "In statistical relational learning (SRL), there are two fundamental tasks:\n",
    "\n",
    "- Entity classification, i.e., assign types and categorical properties to entities.\n",
    "- Link prediction, i.e., recover missing triples.\n",
    "\n",
    "In both cases, missing information are expected to be recovered from neighborhood structure of the graph. Here is the example from the R-GCN paper:\n",
    "\n",
    "“Knowing that Mikhail Baryshnikov was educated at the Vaganova Academy implies both that Mikhail Baryshnikov should have the label person, and that the triple (Mikhail Baryshnikov, lived in, Russia) must belong to the knowledge graph.”\n",
    "\n",
    "R-GCN solves these two problems using a common graph convolutional network extended with multi-edge encoding to compute embedding of the entities, but with different downstream processing:\n",
    "\n",
    "- Entity classification is done by attaching a softmax classifier at the final embedding of an entity (node). Training is through loss of standard cross-entropy.\n",
    "(实体分类是通过在实体（节点）的最终嵌入处附加softmax分类器来完成的。训练是通过丧失标准交叉熵。)\n",
    "\n",
    "- Link prediction is done by reconstructing an edge with an autoencoder architecture, using a parameterized score function. Training uses negative sampling.\n",
    "(通过使用参数化分数函数利用自动编码器架构重建边缘来完成链路预测。培训使用负面抽样。)\n",
    "\n",
    "This tutorial will focus on the first task to show how to generate entity representation. Complete code for both tasks can be found in DGL’s github repository.\n",
    "\n",
    "## Key ideas of R-GCN\n",
    "\n",
    "![](img/RGCN1.png)\n",
    "![](img/RGCN2.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
